package com.example.tbplus14.Test;

import sun.nio.ch.DirectBuffer;

import java.nio.ByteBuffer;

public class ByteBufferTest {

    public static void main(String[] args)throws Exception {
        ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024 * 2000);
        System.out.println("start");
        Thread.sleep(5000);
        clean(buffer);//执行垃圾回收
//     System.gc(); //执行Full gc进行垃圾回收
        System.out.println("end");
        Thread.sleep(5000);

    }

    public static void clean(final ByteBuffer byteBuffer) {
        if (byteBuffer.isDirect()) {
            ((DirectBuffer)byteBuffer).cleaner().clean();
        }
    }

}
